/**
 * Created by smp on 2017/4/24.
 */
var modelPath=ROOT_PATH+'/majorHazard/assessmentReport/';
$('#facilitiesAndParts').textbox({
    required: true,
    icons: [{
        iconCls: 'icon-search',
        handler: function () {
            WindowManager.openLayer({
                type: 2,
                title: '关键装置/要害部位',
                area: ['90%', '70%'],
                content: ROOT_PATH + '/majorHazard/informationRegistration/simpleList.shtml',
                callBack:function(data){
                    $("#facilitiesAndParts").textbox("setValue",data[0].devicePartName);
                    $("#level").val(data[0].level);
                    $("#contractorName").val(data[0].contactContractorName);
                }
            });
        }
    }],
    editable: false
});
$("#btn_save").click(function () {
    var index=layer.confirm('是否确定保存？', {
        btn: ['确定','取消'] //按钮
    }, function(){
        $('#form1').form('submit', {
            url: modelPath+'edit.shtml',

            onSubmit: function (param) {
                var isValid = $(this).form('validate');
                if (!isValid) {
                    layer.close(index);
                    layer.msg("请正确填写表单")
                }
                return $(this).form('validate');
            },
            success: function (result) {
                result = $.parseJSON(result);
                if (result.success){
                    //$.messager.progress('close');	// 如果提交成功则隐藏进度条
                    layer.msg(result.message,{time:1000,icon:1},function () {
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                        $.getIframeWindow().$('#dg1').datagrid('load');
                    });
                }else {
                    //$.messager.progress('close');	// 如果提交成功则隐藏进度条
                    parent.layer.msg(result.message,{time:1000,icon:2});
                }
            }
        });
    });
});
/**
 * 时间限制
 * @param month
 * @returns {*}
 */
function toMonth(month) {
    month=month+1;
    if(month<10)
        return "0"+month;
    else
        return month;
}
function toDate(date) {
    if(date<10)
        return "0"+date;
    else
        return date;
}
$(function(){
    $("#beginTime").datebox().datebox("calendar").calendar({
        validator:function(date){
            var dateTime=date.getFullYear()+"-"+toMonth(date.getMonth())+"-"+toDate(date.getDate());
            var endTime=$("#endTime").textbox("getValue");
            if(endTime==null||endTime==""){
                return true;
            }else {
                return dateTime<=endTime;
            }
        }
    });
    $("#endTime").datebox().datebox("calendar").calendar({
        validator:function(date){
            var dateTime=date.getFullYear()+"-"+toMonth(date.getMonth())+"-"+toDate(date.getDate());
            var beginTime=$("#beginTime").textbox("getValue");
            if(beginTime==null||beginTime==""){
                return true;
            }else {
                return dateTime>=beginTime;
            }
        }
    });
});